package com.example.demo;

import com.example.demo.config.BeanConfig;
import com.example.demo.config.UserConfig;
import com.example.demo.config.UserInfo;
import com.example.demo.controller.Usercontroller;
import com.example.demo.repo.UserRepository;
import com.example.demo.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;


@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        //Spring上下文
        ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
//        //从context中获取bean
        Usercontroller bean = context.getBean(Usercontroller.class);
        bean.doController();
//
//        //根据类名获取bean
//        UserService bean1 = context.getBean(UserService.class);
//        bean1.doservice();
//
//        //根据名称获取bean
//        UserService userService = (UserService) context.getBean("userService");
//        userService.doservice();
//
//        //根据名称和类型拿到bean
//        UserService userService2 = context.getBean("userService", UserService.class);
//        userService2.doservice();
//
//        UserRepository bean2 = context.getBean(UserRepository.class);
//        bean2.doRepository();
//
//        UserConfig bean3 = context.getBean(UserConfig.class);
//        bean3.doConfig();
//
//        UserInfo bean4 = (UserInfo) context.getBean("userInfo");    //当一个类型存在多个Bean时,我们就不能使用类型获取对象
//        System.out.println(bean4);
        //context.getBean("userInfo", UserInfo.class);  //也可以通过"名称"加上"类型"来获取


    }

}
